package com.taoyige.bean;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.w3c.dom.Comment;

import com.taoyige.AppException;
import com.taoyige.common.JacksonJsonUtil;

/**
 * 数据操作结果实体类
 * @author peter
 * @version 1.0
 * @created 2014-11-14
 */
@JsonIgnoreProperties(ignoreUnknown=true)
public class Result implements Serializable {

	private int errorCode;
	private String errorMessage;
	
	
	public boolean OK() {
		return errorCode == 1;
	}

	/**
	 * 解析调用结果
	 * 
	 * @param stream
	 * @return
	 * @throws Exception 
	 */
	public static Result parse(InputStream ins) throws Exception {
		Result res = (Result) JacksonJsonUtil.jsonToBean(ins, Result.class);
		return res;
	}

	public int getErrorCode() {
		return errorCode;
	}
	public String getErrorMessage() {
		return errorMessage;
	}
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}


	@Override
	public String toString(){
		return String.format("RESULT: CODE:%d,MSG:%s", errorCode, errorMessage);
	}
}
